#pragma once
#include <map>
#include "ITradeAdapter.h"
namespace tradeadapter
{
	namespace demo
	{
		struct DemoParam
		{
			bool DealedAll;
			double Poundage;
			//
			bool usedb;
			std::string dbname;
			std::string dbusr;
			std::string dbpwd;
			std::string clientid;

		};
		class CDemoTradeAdapter : public ITradeAdapter
		{
		public:
			CDemoTradeAdapter(void);

			bool InitAccountInfo();

			virtual ~CDemoTradeAdapter(void);

			virtual bool Initialize( void* param = NULL );

			virtual bool InitializeByXML( const TCHAR* fpath );

			virtual int EntrustOrder( Order order );

			virtual bool CancelOrder( OrderID orderid );

			virtual int QueryOrder( OrderID id );

			virtual void UnInitialize();

			virtual bool QueryDealedOrders( std::list<DealedOrder>* pres );

			virtual bool QueryAccountInfo( BasicAccountInfo* info );

			virtual bool QueryPostions( std::list<PositionInfo>* pPoss,const TCHAR* pstock = NULL );

			virtual bool GetLastError( std::pair<int,tstring>* pError );
			virtual bool UpdatePosition(DealedOrder order);


			void SetOrderIDIndex();

		private:	
			DealedOrder CreateRandomDealedOrder(Order order,int curpos);

			virtual bool IsInitialized();

			virtual bool QueryEntrustInfos( std::list<EntrustInfo>* pinfo );

			typedef std::map<OrderID, Order>::iterator ITERATOR;
			
			
			BasicAccountInfo m_info;

			std::list<PositionInfo> m_pos;

			 std::list<DealedOrder> m_dealedorders;



			std::pair<int,tstring> m_lasterr;

			DemoParam m_param;
			int m_orderidIndex;


		};

	}
}